package D12_6z.IO_空参构造_调用get_set方法_1;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        File file = new File("src/Y2019/M12_/D12_6z/IO_空参构造_调用get_set方法_1/data1.txt");
        List<String> strings = FileUtils.readLines(file);
        Class<?> aClass = Class.forName("Y2019.M12_.D12_6z.IO_空参构造_调用get_set方法_1.Person");
        Field d1 = aClass.getDeclaredField("id");
        Field d2 = aClass.getDeclaredField("name");
        Field d3 = aClass.getDeclaredField("age");
        d1.setAccessible(true);
        d2.setAccessible(true);
        d3.setAccessible(true);
        Object o = aClass.newInstance();
        for (int i = 0; i < strings.size(); i++) {
            String[] split = strings.get(i).split("=");
            if (d1.getName().equals(split[0])){
                d1.set(o,split[1]);
            }
            if (d2.getName().equals(split[0])){
                d2.set(o,split[1]);
            }
            if (d3.getName().equals(split[0])){
                d2.set(o,split[1]);
            }
        }

    }
}
